<template>
    <div></div>
</template>

<script>
import { authApi } from "@/api/user";
import { mapRoutesSource } from "@/util/util";
import { authLoginUrl } from '@/config/env';
export default {
    data() {
        return {
            
        };
    },
    mounted() {
        this.auth();
        console.log(authLoginUrl)
    },
    methods: {
        auth() { 
            if (this.getQueryVariable('token')) {
                // window.location.href = 'http://10.65.44.28:10099/#/login';
                // 获取token 调接口 获取登录token 跳转到首页
                // console.log(window.location.href.split('?')[0]);
                // this.$router.replace({
                //     path: '/login'
                // })
                // 调接口
                const params = {
                    tokenString: this.getQueryVariable('token')
                }
                authApi(params).then((res) => {
                    this.$store.dispatch('authLogin', res.data.data).then(() => {
                        // console.log(res)
                        sessionStorage.setItem('logOut', true)
                        window.history.pushState('', '', `${authLoginUrl}/#/wel`);
                        this.$router.push('/wel/index') // 默认跳转首页
                        this.$store.dispatch('GetRoutes').then((data)=> {
                        let temp = mapRoutesSource(data); // 处理路由
                            this.$router.$avueRouter.addRoutesDynamic(temp); // 添加动态路由
                        }); // 获得系统的路由
                        this.$store.dispatch('GetPermissions'); // 获得Permissions权限 用于判断按钮的权限 其他按钮
                        this.$store.dispatch("GetTopMenu").then(res => {
                            // 处理菜单数据
                            let menus = mapRoutesSource(res); // 处理菜单
                            this.$store.commit('NAV_MENU_LIST', menus);
                            let parentId = res.length > 0 ? res[0].id : 0;
                            if (parentId) this.$store.dispatch("GetMenu", parentId); // 更新左侧菜单
                        });
                    });
                });
                // window.history.pushState('', '', 'http://10.65.44.28:10099/#/login');
                // this.$router.replace({
                //     path: '/login'
                // });
            } else {
                window.location.href = `http://sso.justech.com/v3/?back_url=${authLoginUrl}&AppID=MES`;
            }
        },
        // 获取url 参数
        getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                if (pair[0] == variable) {
                    return pair[1];
                }
            }
            return false;
        }
    },
    
};
</script>

<style>
</style>